#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights)
    {
        int n = names.size();
        vector<int> index(n);
        for (int i = 0; i < n; i++) index[i] = i;
        sort(index.begin(), index.end(), [&](int p1, int p2) {return heights[p1] > heights[p2]; });
        vector<string> ret;
        for (auto& e : index) ret.push_back(names[e]);
        return ret;
    }
};
class Solution {
public:
    vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2)
    {
        int n = nums1.size();
        vector<int> index2(n);
        for (int i = 0; i < n; i++) index2[i] = i;
        sort(index2.begin(), index2.end(), [&](int a1, int a2) { return nums2[a1] < nums2[a2]; });
        sort(nums1.begin(), nums1.end());
        int left = 0, right = n - 1;
        vector<int> ret(n);
        for (int i = 0; i < n; i++)
        {
            if (nums1[i] <= nums2[index2[left]]) ret[index2[right--]] = nums1[i];
            else ret[index2[left++]] = nums1[i];
        }
        return ret;
    }
};